import * as proxy from '../proxy';
import ServiceBase from '../base';
import {SharePageProxy} from '../proxies/share-page-proxy';

const GET_SHARE = '/share';
const GET_SHARES = '/shares';
const GET_ACCOUNTS = '/accounts';

class ShareService extends ServiceBase {
    getShare = (data) => {
        // TODO 最后的,shareId是否有用 let promise = super.get(`/projects/${shareId}`, shareId)
        let promise = super.getWithoutToken({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares/${data.sharedId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    shareVersion = (data) => {
        let promise = super.post({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/files/${data.fileId}/versions/${data.version}${GET_SHARE}`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    shareView = (data) => {
        let promise = super.post({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/files/${data.fileId}/versions/${data.version}/views/${data.viewId}${GET_SHARE}`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    shareFile = (data) => {
        let promise = super.post({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/files/${data.fileId}${GET_SHARE}`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    shareFolder = (data) => {
        let promise = super.post({
            url: `${GET_ACCOUNTS}/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/share`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    shareModel = (data) => {
        let promise = super.post({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}${GET_SHARES}/models`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteShare = (data) => {
        let promise = super.delete({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares/${data.shareId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteMultiplyShare = (data) => {
        let promise = super.delete({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares`,
            headers: {'content-Type': 'application/json'},
            data: data.shareIdArray,
        });
        return proxy.httpResultProxy(promise);
    };
    getUserShare = (data) => {
        let promise = super.get({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares`,
        });
        return proxy.httpResultProxy(promise, SharePageProxy);
    };
    getShareToken = (data) => {
        let promise = super.postWithoutToken({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares/${data.sharedId}/token`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    getPassword = (data) => {
        let promise = super.get({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/shares/${data.sharedId}/password`,
        });
        return proxy.httpResultProxy(promise);
    };
    sendShareMsg = (data: any) => {
        let promise = super.post({
            url: `/shares/${data.shareId}/sendmsg`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
    addReceivedShare = (data) => {
        let promise = super.post({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/receivedShares/${data.sharedId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    getReceivedShare = (data) => {
        let promise = super.get({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/receivedShares`,
            params: data.query,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteReceivedShare = (data) => {
        let promise = super.delete({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/receivedShares`,
            data: data.body,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {ShareService};
